package com.atguigu.ggkt.vod.service.impl;

import com.atguigu.ggkt.model.vod.Teacher;
import com.atguigu.ggkt.vo.vod.TeacherQueryVo;
import com.atguigu.ggkt.vod.mapper.TeacherMapper;
import com.atguigu.ggkt.vod.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2023-03-28
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    //分页条件查询
    @Override
    public IPage<Teacher> getAllPage(Page<Teacher> page, TeacherQueryVo teacherQueryVo) {
        if(teacherQueryVo == null){
            IPage<Teacher> teacherPage = baseMapper.selectPage(page, null);
            return teacherPage;
        }

        LambdaQueryWrapper<Teacher> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(teacherQueryVo.getName() != null) {
            lambdaQueryWrapper.like(Teacher::getName,teacherQueryVo.getName());
        }
        if(teacherQueryVo.getLevel() != null) {
            lambdaQueryWrapper.eq(Teacher::getLevel,teacherQueryVo.getLevel());
        }
        if(teacherQueryVo.getJoinDateBegin() != null) {
            lambdaQueryWrapper.ge(Teacher::getJoinDate,teacherQueryVo.getJoinDateBegin());
        }
        if(teacherQueryVo.getJoinDateEnd() != null) {
            lambdaQueryWrapper.le(Teacher::getJoinDate,teacherQueryVo.getJoinDateEnd());
        }

        IPage<Teacher> teacherIPage = baseMapper.selectPage(page, lambdaQueryWrapper);
        return teacherIPage;
    }
}
